<%@page import="com.sbdcpn.utils.db.BaseDAO"%>
<%
	//String strSQL = "select count(*) as pagenum , trim(to_char(nvl(sum(in_material.in_sum),0.00),'999999999999.99')) as sum_in   from finance_lifespan,in_material ";
    String strSQL = "select count(*) as pagenum , sum(in_material.in_sum-DECODE(in_material.IS_SELF,1,0,nvl(trim(to_char(in_material.road_fee_tax*(1-nvl(decode(in_material.is_tax,'1',0,in_material.road_fee_taxrate),0.00)*0.01)*in_material.in_qty,'999999999.99')),0.00))) as sum_in   from finance_lifespan,in_material ";
	String strWhere = RequestUtil.getStringParameter(request ,"where_sql");
	String strValue = RequestUtil.getStringParameter(request ,"where_value");
	String strType = RequestUtil.getStringParameter(request ,"where_type");
	String pageType = RequestUtil.getStringParameter(request ,"pageType");

	if (pageType.equals("grid")) {
		if  (!strWhere.equals("")) {
			strWhere = " where " + strWhere + " AND nvl(finance_lifespan.auditing,'0')='0'  and in_material.stock_in_id = finance_lifespan.stock_in_id  ";
		} else {
			strWhere = " where nvl(finance_lifespan.auditing,'0')='0'  and in_material.stock_in_id = finance_lifespan.stock_in_id  ";
		}
	}else if (pageType.equals("query")){
		if  (!strWhere.equals("")) {
			strWhere = " where " + strWhere ;
		}
	}

	BaseDAO dao = BaseDAO.getInstance();

	Map mpCnt = null;

	System.out.println("--------finance_lifespan SUM-IN SQL ====="+strSQL+strWhere);

	if (strWhere.indexOf("notDoQuery") == -1) {
		if (!strValue.equals("")) {
			mpCnt = dao.queryOneRow(strSQL + strWhere ,new String[]{strValue ,strType});
		} else {
			mpCnt = dao.queryOneRow(strSQL + strWhere);
		}
	} else {
		mpCnt = FactoryUtil.newMap();
	}
%>

<SCRIPT LANGUAGE="JavaScript">
<!--
function f_setGrid() {
	f_setAccountFlag();
}

function f_setAccountFlag() {
	//alert(document.all("extend_param").value);
	var yearObj = document.all("txtYear");
	var yearMonth = document.all("extend_param").value;

	var curdate = new Date();
	//alert(curdate.getYear());
	yearObj.value = curdate.getYear();

	var monthObj = document.all("selMonth");
	//alert(curdate.getMonth());
	var curMonth = curdate.getMonth() + 1;
	if (curMonth.length == 1) curMonth = "0" + curMonth;
	monthObj.value = "";//curMonth;

	if (yearMonth != "") {
		yearObj.value = yearMonth.split("-")[0];
		monthObj.value = yearMonth.split("-")[1];
	}
}

function f_month_where() {
	//alert(document.all("where_sql").value + "||" + document.all("orgwhere_sql").value);
	//var where_sql = "to_char(in_material.in_date ,'yyyy-mm') = ?";
	 var where_sql = "in_material.account_flag = ?";

	var orgwhere_sql = document.all("orgwhere_sql").value;
	var orgwhere_value = document.all("orgwhere_value").value;
	var orgwhere_type = document.all("orgwhere_type").value;

	if (orgwhere_sql == "") {
		orgwhere_sql = document.all("where_sql").value;
		orgwhere_value = document.all("where_value").value;
		orgwhere_type = document.all("where_type").value;

		document.all("orgwhere_sql").value = orgwhere_sql;
		document.all("orgwhere_value").value = orgwhere_value;
		document.all("orgwhere_type").value = orgwhere_type;
	}

	var yearObj = document.all("txtYear");
	var monthObj = document.all("selMonth");

	var where_value = yearObj.value + "-" + monthObj.value;
	document.all("extend_param").value = where_value;
	var where_type = "string";

	if (orgwhere_sql != "") {
		where_sql = where_sql + " and (" + orgwhere_sql + ")";
		where_value += ";" + orgwhere_value;
		where_type += ";" + orgwhere_type;
	}

	if (monthObj.value == "") {
		where_sql = orgwhere_sql;
		where_value = orgwhere_value;
		where_type = orgwhere_type;
	}

	document.all("where_sql").value = where_sql;
	document.all("where_value").value = where_value;
	document.all("where_type").value = where_type;

	f_reloadPage();
}


//-->
</SCRIPT> 
<table class="gridTbl">
<tr class="gridData">
	<td class="gridData" >
	<input type="text" name="txtYear" id="txtYear" size="5" value=""> -
	<select name="selMonth" id="selMonth" onchange="f_month_where(this);">
	<option value=""></option>
	<option value="01">01</option>
	<option value="02">02</option>
	<option value="03">03</option>
	<option value="04">04</option>
	<option value="05">05</option>
	<option value="06">06</option>
	<option value="07">07</option>
	<option value="08">08</option>
	<option value="09">09</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	</select>
	<eam:message key="column.GROUPAUDIT_PROVIDER_V.view_groupaudit_provider.num" />:<%=(String)mpCnt.get("pagenum")%>
	<eam:message key="column.FINANCE_PROVIDER.finance_provider.sum_in" />:<%=(String)mpCnt.get("sum_in")%>
	</td>
</tr>
</table>